home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 157_01 / qed1 < prev    next >
Text File  |  1987-10-10  |  12KB  |  561 lines

  1. /*  VERSION 0004  (DATE: 03/03/87)  (TIME: 11:07)  */
  2. /*
  3.     e (qed) screen editor
  4.  
  5.     (C) G. Nigel Gilbert, MICROLOGY, 1981
  6.  
  7.     August-December 1981
  8.  
  9.     Modified: Aug-Dec     1984:  BDS-C 'e'(vers 4.6a) to 'qe' (J.W.Haefner)
  10.               March        1985:  BDS-C 'qe' to DeSmet-C 'qed' (J.W.Haefner)
  11.  
  12.     FILE: qe1
  13.  
  14.     FUNCTIONS: dirmsk, 
  15.         printdirectory, envir, files, putonoff, getnumb, getlow
  16.  
  17.     PURPOSE:  environment; change files.
  18.  
  19. */
  20.  
  21. #include "qed.h"
  22.  
  23. #define EXTENT 12
  24. #define RECORDS 15
  25. #define EXTSIZ 128
  26.  
  27. #if CPM            /*NOTE: <<NOT>> debugged for CP/M86*/
  28. dirmsk()
  29.  
  30. {
  31.     char *pattp;
  32.     sint drv;
  33.  
  34.     pattp = patt;     /* use pattern find array to save extnl space */
  35.     if (scans(patt,FILELEN) == ESCKEY) return (YES);
  36.     drv = curdsk+1;        /* drv = num for bdos file search */
  37.     if (!*pattp) pattp = "*.*";
  38.     else
  39.         if (patt[1] == ':') {
  40.             if (  ((drv = (toupper(*pattp) - '@')) < 1) || (drv > 16)  )
  41.                 drv = curdsk+1;
  42.             pattp += 2;
  43.         }
  44.     expmsk(drv,pattp);
  45. }
  46.  
  47. expmsk(drv,str)  /* create wildcard cp/m filename from str*/
  48. sint drv;
  49. char *str;
  50.  
  51. /*  input:  str: a user input string to expand to legal cp/m wildcard name
  52.     output:    dirmsk: a string wh/ is a legal cp/m wildcard file name */
  53.  
  54. {          /* 10 */
  55.     sint stop,inmsk,inwild;
  56.     char c, wildarray[15], *wildname;
  57.  
  58.     for (inwild=0;inwild<15;wildarray[inwild++]=' ');
  59.     wildname = wildarray;    /* use pattern change array to save space */
  60.     wildname[0] = drv;
  61.     wildname[12] = '?';
  62.     wildname[14] = '\0';
  63.     stop = 8;
  64.     inmsk = 0;        /* index for input mask */
  65.     inwild = 1;        /* index for directory mask (output) */
  66.     while ((wildname[inwild]) && (str[inmsk]))  {
  67.         switch (c=str[inmsk++])  {    /*30*/
  68.         case '*' :
  69.             for( ; (inwild <= stop);inwild++)
  70.                 wildname[inwild] = '?';
  71.             stop = 11;
  72.             break;
  73.         case '.' :
  74.             inwild = 9;
  75.             stop = 11;
  76.             break;
  77.         default:
  78.             wildname[inwild++] = toupper(c);
  79.             break;
  80.         }    /*30*/
  81.     }
  82.     printdirectory(wildname);
  83. }    /*10*/
  84.  
  85.  
  86. printdirectory(wildname)
  87. char *wildname;
  88. {
  89.     int y, *dsm, cols, loc, i, ndb, pos;
  90.     unsigned blsr, used, recs;
  91.     char c, a, entriesonline, *bsh, exm, al0;
  92.     char *parms;
  93.     sint dmabuf[128],drive;
  94.  
  95.     putclr();
  96.     gotoxy(0,6);
  97.     putstr("Can't print directory yet.");
  98.     _os(SETDMA,dmabuf);
  99.     drive = wildname[0]-1;
  100.     gotoxy(0,6);
  101.     putstr("Directory of "); 
  102.     putch(drive + 'A');
  103.     putch(':');
  104.     if (curdsk != (drive) && seldisk(drive) != FAIL) {
  105.         putstr("  |(default drive is ");
  106.         putch(curdsk+'A');
  107.         putstr(":|)");
  108.         }
  109.     used=0;
  110.     parms=_os(DSKPARAMS);
  111.     bsh = parms+2;
  112.     exm = *(parms+4);
  113.     dsm = parms+5;
  114.     al0 = *(parms+9);
  115.     blsr = (1 << *bsh)/8;
  116.      /*block size in kbytes*/
  117.     for(ndb=0;al0;al0 <<= 1, ndb++);
  118.     entriesonline=0;
  119.     begdim(); 
  120.     deleteline(2,(y=8));
  121.  
  122.     pos=_os(SEARCH1,wildname);
  123.     while (pos != 0xff) {
  124.         loc= pos << 5;
  125.         recs = (exm) ? EXTSIZ*(dmabuf[loc+EXTENT]%((exm)+1))
  126.                  + dmabuf[loc+RECORDS]
  127.                 : dmabuf[loc+RECORDS];
  128.         used += (recs/(8*blsr))*blsr;
  129.         if (recs%(8*blsr)) used += blsr;
  130.         if (dmabuf[loc+EXTENT] <= exm) {
  131.             for (i=1, cols=0; i < 12; i++) {
  132.                 c= dmabuf[loc+i] & 0x7f;
  133.                 if (i == 9 && c != ' ') {
  134.                     cols++;
  135.                     putch('.');
  136.                     }
  137.                 if (c != ' ') {
  138.                     cols++;
  139.                     putch( (i >= 9 ? tolower(c) : c));
  140.                     }
  141.                 }
  142.             while (cols++ < 12) putch(' ');
  143.             if (++entriesonline == 5) {
  144.                 deleteline(2,++y);
  145.                 if (y == SHEIGHT) { 
  146.                     putstr("[||<cr>| for MORE...]");
  147.                     a = getkey();
  148.                     begdim();
  149.                     delpage((y=8));
  150.                     gotoxy(2,8);
  151.                 /*    goto incomplete;     */
  152.                     }
  153.                 entriesonline=0;
  154.                 }
  155.             else putstr(" :  ");
  156.             }
  157.         pos=_os(SEARCHN,wildname);
  158.         }
  159.     gotoxy(50,SHEIGHT);
  160.     for (i=1;((wildname[i]=='?') && (i<12)); i++);
  161.     if (i==12) {
  162.         putstr("Free = ");
  163.         uspr((((*dsm+1)-ndb)*blsr)-used);
  164.         putstr("k  ");
  165.         }
  166.     putstr("Files = ");
  167.     uspr(used);
  168.     putch('k');
  169.     if (curdsk != drive) seldisk(curdsk);
  170.     enddim(); 
  171.     gotoxy(0,0);
  172.     return;
  173. }
  174. #endif
  175.  
  176. #if DOS2
  177.  
  178. dirmsk()    /* in MSDOS 2.x just pass the string to showdir
  179.                maintain dirmsk call for other functions   */
  180. {
  181.     char *pattp;
  182.  
  183.     pattp=patt;
  184.     if (scans(patt,FILELEN) == ESCKEY) return YES;
  185.     if (!*pattp) pattp = "*.*";
  186.     showdir(pattp);
  187. }
  188.  
  189. showdir(msk)    /* show msdos directory from ambiguous mask */
  190. char *msk;        /* assumes vers.2.x, allows path names */
  191. {
  192.     char dtabuf[43], *dirsp, curdir[64], *curdirp;
  193.     char *bufp,first, driven, drivel, entriesonline, a, c;
  194.     long fsize,*sizep,used,free;
  195.     int x,y,i;
  196.  
  197.     /* init display */
  198.     putclr();
  199.         /* has a drive been specified?*/
  200.     for (i=0;( (c=msk[i++]) && (c != ':') ););
  201.     if (c) {
  202.         drivel = toupper(msk[(i-=2)]);
  203.         {
  204.         if ( ((driven = drivel-'A') < 0) || (driven > 15)) {
  205.             driven=curdsk;
  206.             drivel=driven+'A';
  207.             }
  208.         }
  209.         }
  210.     else {
  211.         driven=curdsk;
  212.         drivel=driven+'A';
  213.         }
  214.     curdirp=curdir;
  215.     *curdirp=0;
  216.     gotoxy(0,6);
  217.     if (getpath(curdirp,(driven+1))==FAIL) return NO;
  218.     putstr("Directory of ");
  219.     dispch(drivel);
  220.     putstr(":\\");
  221.     putstr(curdirp);
  222.     if (curdsk != (driven) && seldisk(driven) != FAIL) {
  223.         putstr("  |(default drive is ");
  224.         putch(curdsk+'A');
  225.         putstr(":|)");
  226.         }
  227.     
  228.     /* get disk free space */
  229.     _rax = (FREESP << 8);
  230.     _rds = -1;
  231.     _rdx = driven+1;
  232.     _rcx = 0x00;
  233.     _doint(DOSINT);
  234.     if(_rax==0xffff) {
  235.         error("Bad drive");
  236.         return (_rax);
  237.         }
  238.         /*use "1L" to force unsigned to long conversion*/
  239.     free = 1L*(_rax) * (_rbx) * (_rcx);
  240.     deleteline((x=2),(y=8));
  241.     dirsp="=||dir|";
  242.     entriesonline=0;
  243.     used=0;
  244.     for (i=0;i<43;i++)
  245.         dtabuf[i]=0;
  246.     _os(SETDMA,dtabuf);
  247.     first=TRUE;
  248.     do    {
  249.         _rax = ( (first) ? (0x4e << 8) : (0x4f << 8) );    /* find first&next */
  250.         _rdx = msk;                /* point to path */
  251.         _rds = -1;                /* use current ds */
  252.         _rcx = 0x30;            /* show normal, dir and archived files */
  253.         _doint(DOSINT);            /* goto DOS */
  254.         if (_rax == 2) {        /* bad path */
  255.             error("Bad path");
  256.             return NO;
  257.             }
  258.         if ( (_rax != 18) ) {    /* name is found */
  259.             begdim();
  260.             first=FALSE;
  261.             sizep=&dtabuf[0x1a];
  262.             fsize= *sizep;
  263.             used+=fsize;
  264.             bufp=&dtabuf[0x1e];
  265.             putstr(bufp);
  266.             if (dtabuf[0x15]==0x10) putstr(dirsp);    /*entry is directory*/
  267.                 /*put code to show if archive bit set, here */
  268.             if ((++entriesonline<5))
  269.                 gotoxy((x+=15),y);
  270.             else {
  271.                 deleteline((x=2),++y);
  272.                 if (y==SHEIGHT) {
  273.                     putstr("[||<cr>| for MORE...]");
  274.                     a=getkey();
  275.                     begdim();
  276.                     delpage((y=8));
  277.                     gotoxy((x=2),y);
  278.                     }
  279.                 entriesonline=0;
  280.                 }
  281.             }
  282.         }
  283.     while ( (_rax != 18) );
  284.     gotoxy(40,SHEIGHT);
  285.     putstr("Free = ");
  286.     uspr(0,free);
  287.     putstr("   Files = ");
  288.     uspr(0,used);
  289.     if (curdsk != driven) seldisk(curdsk);
  290.     enddim();
  291.     gotoxy(0,0);
  292.     return (_rax);
  293. }
  294.  
  295. #endif
  296.  
  297. envir()
  298. {
  299.     char c;
  300.     int maxlines;
  301.     struct addr anaddr;
  302.  
  303.     puttext();
  304.     do {
  305.         putclr();
  306.         putstatusline(cline);
  307.         gotoxy(0,3);
  308.         putstr("Edit context:  |(|F| for file context)|\n\n");
  309.         putstr("A|uto indent                ");
  310.         putonoff(autoin);
  311.         putstr("B|ackup altered file        ");
  312.         putonoff(backup);
  313.         putstr("D|efault backup path        ");
  314.         putstr(bakpath);
  315.         putstr("\nT|ab stops every            ");
  316.         uspr(tabwidth,0L);
  317.         putstr("\nS|trip trailing blanks      ");
  318.         putonoff(!trail);
  319.         putstr("L|ine and column            ");
  320.         putonoff(displaypos);
  321. #if WWRAP
  322.         putstr("R|ight margin               ");
  323.         uspr(rtmarg,0L);
  324. #endif
  325.         putstr("\nH|orizontal scroll page     ");
  326.         putonoff(blockscroll);
  327.         putstr("E|xpert prompts             ");
  328.         putonoff(expert);
  329.         putstr("O|nscreen help              ");
  330.         putonoff(helpon);
  331. #if VRSNNUM
  332.         putstr("V|ersion update             ");
  333.         putonoff(version);
  334. #endif
  335. /*
  336.         putstr("\n|Memory allows for no more than ");
  337.         uspr( ((slotsinmem-2)*(PAGESIZE/(sizeof(anaddr)))) ,0L);
  338.         putstr("| lines of text");
  339. */
  340.         putstr("\n|Current line ");
  341.         uspr(cline,0L);
  342.         putstr(" is |");
  343.         maxlines=(slotsinmem-2)*(PAGESIZE/(sizeof(anaddr)));
  344.         uspr( (unsigned)(((long)cline*100)/maxlines),0L);
  345.         putstr("% |of ");
  346.         uspr(maxlines,0L);
  347.         putstr(" maximum lines.");
  348.         putstr("\n\n\nTo change context, enter letter, or |Q| to return: ");
  349.         switch((c=getlow())) {
  350.         case 'a': 
  351.             autoin= !autoin; 
  352.             break;
  353.         case 'b': 
  354.             backup= !backup;